<!-- 新增编辑查看 -->
<template>
  <el-dialog :visible.sync="params.show" @open="init" :before-close="cancel" class="dialog-form" width="515px">
    <DialogFormTitle slot="title" :title="$t(params.title)" />
    <el-form :model="formData" ref="formData" :inline="true" label-position="top" :disabled="params.title === 'button.Details'">
      <el-form-item label="名称" prop="name" :rules="[V.required]">
        <FInput v-model.trim="formData.name" />
      </el-form-item>
      <el-form-item label="时间" prop="time" :rules="[V.required]">
        <FDatePicker v-model="formData.time" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <FSelect v-model="formData.state" :options="DISABLE" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <FTextarea v-model.trim="formData.remark" />
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button type="info" @click="cancel">{{$t('button.Cancel')}}</el-button>
      <el-button type="primary" @click="submit" :loading="loading" v-if="params.title !== 'button.Details'">{{$t('button.OK')}}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import mixinDialogForm from '@/mixin/dialog-form'
// import { test } from '@/api/base';
import { DISABLE } from '@/constants/basic-data'

export default {
  mixins: [mixinDialogForm],
  props: {
    params: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      DISABLE,
      loading: false,
      formData: {}
    }
  },
  methods: {
    /**
     * 弹框初始化
     */
    init() {
      this.formData = {}
      if (this.params.data) {
        this.formData = this.params.data
      }
      this.$refs['formData'] && this.$refs['formData'].resetFields()
    },
    /**
     * 提交
     */
    submit() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          /* let method = null;
          if (this.params.data) {
            method = test;
          } else {
            method = test;
          }
          this.loading = true;
          method(this.formData).then((res) => {
            this.$message.success(this.$t('message.Success'));
            this.$emit('callback'); // 更新列表数据
            this.cancel();
          }).finally(() => {
            this.loading = false;
          }); */
        }
      })
    }
  }
}
</script>
